#include "bg_waypoint.h"

#include "font/font_manager.h"
#include "graphics/graphics_util.h"
#include "script/scripthelper.h"
#ifdef _ENABLE_LUABIND
#include <luabind/luabind.hpp>
#endif // _ENABLE_LUABIND

#include "dd/dd_man.h"
#include "util/timer.h"				// log
#include "util/log.h"				// log
#include "util/common_macros.h"		// macros
#include "util/mmgr.h"		    

using namespace background;
void	BGWaypoint::RenderDebugPos(const math::Vec2& ScreenPos, int ID)
{
	static const	math::Vec2	Size(3/(float)GraphicsUtil::WIDTH, 3/(float)GraphicsUtil::HEIGHT);
	dd::Manager::Instance().AddBox2D(ScreenPos-Size, ScreenPos+Size, ColorRGBA(255, 0, 0, 255));

	if (ID >= 0)
	{
		FontManager::Instance().Print(ScreenPos,
										"WP_%i", ID);
	}

}

void	BGWaypoint::RenderDebug(const math::Vec2& Offset, float Scale)
{
	RenderDebugPos((m_Pos-Offset)*Scale, m_ID);
}

bool	BGWaypoint::IsInside(const math::Vec2& Pos, const math::Vec2& Offset)
{
	static const	math::Vec2	Size(3/(float)GraphicsUtil::WIDTH, 3/(float)GraphicsUtil::HEIGHT);
	return	UTIL_RANGE(m_Pos.x+Offset.x, Pos.x-Size.x, Pos.x+Size.x) && 
			UTIL_RANGE(m_Pos.y+Offset.y, Pos.y-Size.y, Pos.y+Size.y);
}

void	BGWaypoint::Register(LuaPlus::LuaState* _pScript)
{
#ifdef _ENABLE_LUABIND
	lua_State * L = _pScript->GetCState ( );

	luabind::module(L)
    [
	    luabind::class_<BGWaypoint>( "BGWaypoint" )
			.def("GetID",			&BGWaypoint::GetID)
			.def("GetPos",			&BGWaypoint::GetPos)

	];
#endif //_ENABLE_LUABIND
}
